<template>
	<view style="padding-bottom: 180rpx;">
		<view class="mainpadding_top ffffff">
			<view class="flexleft">
				<image :src="dataAll.user.avatar" mode="" class="listheadplimg"></image>
				<view class="flexcolumnbet" style="height: 70rpx;">
					<view class="xiaohei margin_left1">{{dataAll.user.nickname}}</view>
					<view class="xiaohui margin_left1">{{dataAll.createtime_text}}</view>
				</view>
			</view>
			<view class="hei_text bold main_size margin_top2">{{dataAll.title}}</view>
			<view class="xiaohui margin_top2">{{dataAll.description}}</view>
			<view class="flexleft">
				<view class="itemimgBox flexcenter margin_top" v-for="(ite,inde) in dataAll.images_arr" :key="inde" @click="lbtpriview(inde,dataAll.images_arr)">
					<image class="listleftimg radius" :src="ite" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff" v-if="list.data.length">
			<view class="hei_text main_size bold">评论（{{list.total}}）</view>
			<view class="flextop margin_top" :class="index + 1==list.data.length?'':'pdl'"
				v-for="(item,index) in list.data" :key="item.id" @click="zhuijia(item.id)">
				<image :src="item.user.avatar" mode="" class="listheadplimg"></image>
				<view class="margin_left1" style="width: 100%;">
					<view class="hei_text main_size bold">{{item.user.nickname}}</view>
					<view class="margin_top1 xiaohei">{{item.content}}
						<view class="margin_top1 xiaohui">{{item.createtime_text}}</view>
					</view>
					<!-- 追加评论 -->
					<view class="flextop margin_top" style="justify-content: flex-start;" v-for="ite in item.children"
						:key="ite.id">
						<image :src="ite.author.avatar" mode="" class="listheadplimg2"></image>
						<view class="margin_left1">
							<view class="xiaohui">{{ite.author.nickname}}</view>
							<view class="margin_top1 xiaohei">{{ite.content}}</view>
							<view class="margin_top1 xiaohui">{{ite.createtime_text}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="posibottom mainpadding ffffff">
			<view class="flexbetween bghui ssbox">
				<input type="text" placeholder="善语结善缘,恶语伤人心" :focus="focusState" @blur="focusState=false"
					class="hei_text main_size bold" v-model="content" @confirm="sendmsg">
				<view class="rightss" @click="sendmsg">发送</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				dataAll: {},
				listid: "",
				content: "",
				pid: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				focusState: false
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getDetail()
			this.init()
		},
		methods: {
			lbtpriview(index, arr) {
				var i = arr; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			zhuijia(id) {
				this.focusState = true
				this.pid = id
			},
			sendmsg() {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				if (this.content == "") return
				httpRequest.request('/api/community/addcomment', 'POST', {
					community_id: this.listid,
					content: this.content,
					pid: this.pid,
				}, false, false, true).then(res => {
					this.pid = ""
					this.content = ""
					if (res.code == 1) {
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			getDetail() {

				httpRequest.request('/api/community/getdetail', 'POST', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/community/getcommentlist', 'GET', {
					page: page || 1,
					community_id: _this.listid,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.listheadplimg2 {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		min-width: 60rpx;
	}
</style>